﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;

namespace DataIssue.Service
{
    /// <summary>
    /// 市场规模工具类
    /// </summary>
    public class MarketScaleService
    {
        public List<Entity.MarketScale> GetMarketScales()
        {
            List<Entity.MarketScale> datas = new List<Entity.MarketScale>();
            F10ParamEntity param = new F10ParamEntity("Base", "V_BS_CUST_STK_STST", 2);
            param.Filters = new List<string>();
            param.Filters.Add("STAT_TYPE-in-int=1,3");
            param.OrderBy = "TRADEDATE DESC,STAT_TYPE";
            param.Limit = 2;
            JToken clientData;
            int totalCount = 0;
            F10Query.TryParse(param, false, out clientData, out totalCount);
            if (clientData != null && totalCount > 0)
            {
                double temp = 0f;
                Entity.MarketScale data = new Entity.MarketScale();
                data.Name = "市场均价";
                data.ValueA = Math.Round(clientData[0].J_Double("AVG_PRC", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("AVG_PRC", temp), 2);
                datas.Add(data);

                data = new Entity.MarketScale();
                data.Name = "市净率";
                data.ValueA = Math.Round(clientData[0].J_Double("PB", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("PB", temp), 2);
                datas.Add(data);

                data = new Entity.MarketScale();
                data.Name = "市盈率";
                data.ValueA = Math.Round(clientData[0].J_Double("PE", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("PE", temp), 2);
                datas.Add(data);

                data = new Entity.MarketScale();
                data.Name = "每股收益";
                data.ValueA = Math.Round(clientData[0].J_Double("EPS", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("EPS", temp), 2);
                datas.Add(data);


                data = new Entity.MarketScale();
                data.Name = "成交额(亿元)";
                data.ValueA = Math.Round(clientData[0].J_Double("TVALUE", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("TVALUE", temp), 2);
                datas.Add(data);


                data = new Entity.MarketScale();
                data.Name = "流通市值(亿元)";
                data.ValueA = Math.Round(clientData[0].J_Double("MKTCAP", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("MKTCAP", temp), 2);
                datas.Add(data);


                data = new Entity.MarketScale();
                data.Name = "总市值(亿元)";
                data.ValueA = Math.Round(clientData[0].J_Double("TCAP", temp), 2);
                data.ValueB = Math.Round(clientData[1].J_Double("TCAP", temp), 2);
                datas.Add(data);
            }
            return datas;
        }


    }
}